<!DOCTYPE html>
<!--
/*******************************************************************************
#      ____               __          __  _      _____ _       _               #
#     / __ \              \ \        / / | |    / ____| |     | |              #
#    | |  | |_ __   ___ _ __ \  /\  / /__| |__ | |  __| | ___ | |__   ___      #
#    | |  | | '_ \ / _ \ '_ \ \/  \/ / _ \ '_ \| | |_ | |/ _ \| '_ \ / _ \     #
#    | |__| | |_) |  __/ | | \  /\  /  __/ |_) | |__| | | (_) | |_) |  __/     #
#     \____/| .__/ \___|_| |_|\/  \/ \___|_.__/ \_____|_|\___/|_.__/ \___|     #
#           | |                                                                #
#           |_|                 _____ _____  _  __                             #
#                              / ____|  __ \| |/ /                             #
#                             | (___ | |  | | ' /                              #
#                              \___ \| |  | |  <                               #
#                              ____) | |__| | . \                              #
#                             |_____/|_____/|_|\_\                             #
#                                                                              #
#                              (c) 2010-2012 by                                #
#           University of Applied Sciences Northwestern Switzerland            #
#                     Institute of Geomatics Engineering                       #
#                           martin.christen@fhnw.ch                            #
********************************************************************************
*     Licensed under MIT License. Read the file LICENSE for more information   *
*******************************************************************************/

                       TEST 03: WEBGL_EXT_lose_context
*******************************************************************************/
-->
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="../../../external/closure-library/closure/goog/base.js"></script>
<script type="text/javascript" src="../../../compiled/deps.js"></script>
<script type="text/javascript">goog.require('owg.OpenWebGlobe');</script>

<button onclick="loose_ctx();">Loose Context</button>
<button onclick="restore_ctx();">Restore Context</button>
<script>
   //---------------------------------------------------------------------------
   var g_ctx = -1;
   var WEBGL_EXT_lose_context = null;
   function OnRender(context)
   {
      ogSetTextColor(context, 0,1,0);
      ogDrawText(context, "Hello World", 0, 20);
   }
   //---------------------------------------------------------------------------
   function loose_ctx()
   {
      if (WEBGL_EXT_lose_context)
      {
         WEBGL_EXT_lose_context.loseContext();
         console.log("context lost!");
      }
   }
   //---------------------------------------------------------------------------
   function restore_ctx()
   {
      if (WEBGL_EXT_lose_context)
      {
         WEBGL_EXT_lose_context.restoreContext();
         console.log("context restored!");
      }
   }
   //---------------------------------------------------------------------------
   function main()
   {
      ogSetArtworkDirectory("http://www.openwebglobe.org/art/");
      g_ctx = ogCreateContextFromCanvas("canvas", true);
      var globe = ogCreateGlobe(g_ctx);

      var imgBlueMarble500 =
      {
         url     : ["http://www.openwebglobe.org/data/img"],
         layer   : "World500",
         service : "i3d"
      };

      var elvSRTM_CH =
      {
         url     : ["http://www.openwebglobe.org/data/elv"],
         layer   : "SRTM",
         service : "i3d"
      };

      ogAddImageLayer(globe, imgBlueMarble500);
      ogAddElevationLayer(globe, elvSRTM_CH);

      ogSetRenderFunction(g_ctx, OnRender);
      ogSetBackgroundColor(g_ctx, 0.2,0.6,0.7,1);

      var gl = ogGetGL(g_ctx);
      WEBGL_EXT_lose_context = gl.getExtension("WEBGL_EXT_lose_context") || gl.getExtension("WEBKIT_WEBGL_lose_context") || gl.getExtension("MOZ_WEBGL_lose_context");

   }
   //------------------------------------------------------------------------------
</script>
<body onload="main()" style="padding:0px; margin:0px; overflow:hidden;">
<div style="text-align: center">
   <canvas id="canvas"></canvas>
</div>
</body>
</html>